import {WidgetClass} from "../atom/widget";
import {generateUID} from "@/utils";

export class CameraTracking extends WidgetClass {
  constructor(options = {}) {
    super(options);
    const {ports, UI} = options;
    if (UI) {
      this.UI.data = UI.data;
    } else {
      this.UI.data = {
        cameras: [
          {
            id: `cameras-${generateUID()}`,
            name: "摄像头",
            cameraNum: 1,
            tall: 0,
            upsideDown: false,
            position: {
              left: 50,
              top: 50,
              width: "70",
              height: "70",
            },
            micColor: "bg-color-container",
            micId: "",
            mics: [
              {
                name: "麦克风",
                presetNum: 1,
                id: `mic-${generateUID()}`, //麦克风id
                tall: 0,
                position: {
                  left: 50,
                  top: "200",
                  width: "70",
                  height: "70",
                },
              },
            ],
          },
        ],
        scale: "",
        backgroundImage: "",
        backgroundColor: "bg-color-page", //bg-color-page
        componentColor: "bg-color-container",
        textColor: "text-color-primary",
        contentColor: "text-color-primary",
        activeColor: "brand-color",
      };
      this.UI.data.camerasId = this.UI.data.cameras[0].id;
      this.UI.data.cameras[0].micId = this.UI.data.cameras[0].mics[0].id;
    }
    if (ports) {
      this.ports = ports;
    } else {
      this.ports = this.assembleDefaultPorts();
    }
  }

  assembleDefaultPorts() {
    const superState = super.assembleDefaultPorts();
    return {
      ...superState,
      values: [
        ...superState.values,
        {
          name: "当前摄像机",
          key: "cameraNum",
          type: "int",
          value: 100,
        },
        {
          name: "当前操作的预设",
          key: "presetNum",
          type: "string",
          value: "1",
        },
        {
          name: "当前摄像头参数-倒装",
          key: "upsideDown",
          type: "bool",
          value: false,
        },
        {
          name: "摄像头和麦克风距离-左右",
          key: "horizontal",
          type: "double",
          value: 11.1,
        },
        {
          name: "摄像头和麦克风距离-前后",
          key: "front",
          type: "double",
          value: 11.1,
        },
        {
          name: "摄像头和麦克风距离-上下",
          key: "vertical",
          type: "double",
          value: 11.1,
        },
        {
          name: "摄像头和麦克风距离-直线",
          key: "distance",
          type: "double",
          value: 11.1,
        },
        {
          name: "当前操作麦克风麦克风的3D位置",
          key: "3DPosition",
          type: "map",
          value: {},
        },
      ],
      events: [
        {
          name: "长按事件",
          key: `longPress-${this.id}`,
          eventType: "longPress",
          type: "event",
          value: {
            time: 1 //长按触发时间(秒)
          },
          action: [],
        },
        {
          name: "预设保存",
          key: "savePreset",
          eventType: "custom",
          type: "event",
          action: [
            {
              name: "文本",
              key: "id.valueKey",
              type: "editVar",
              delay: 0,
              value: {
                type: "string",
                value: "savePreset",
              },
            },
          ],
        },
        {
          name: "位置调整",
          key: "positionChange",
          eventType: "custom",
          type: "event",
          action: [
            {
              name: "文本",
              key: "id.valueKey",
              type: "editVar",
              delay: 0,
              value: {
                type: "string",
                value: "positionChange",
              },
            },
          ],
        },
        {
          name: "向左转动",
          key: "panLeft",
          eventType: "custom",
          type: "event",
          action: [
            {
              name: "文本",
              key: "id.valueKey",
              type: "editVar",
              delay: 0,
              value: {
                type: "string",
                value: "panLeft",
              },
            },
          ],
        },
        {
          name: "向右转动",
          key: "panRight",
          eventType: "custom",
          type: "event",
          action: [
            {
              name: "文本",
              key: "id.valueKey",
              type: "editVar",
              delay: 0,
              value: {
                type: "string",
                value: "panRight",
              },
            },
          ],
        },
        {
          name: "左右转动停止",
          key: "panStop",
          eventType: "custom",
          type: "event",
          action: [
            {
              name: "文本",
              key: "id.valueKey",
              type: "editVar",
              delay: 0,
              value: {
                type: "string",
                value: "panStop",
              },
            },
          ],
        },
        {
          name: "向上转动",
          key: "tiltUp",
          eventType: "custom",
          type: "event",
          action: [
            {
              name: "文本",
              key: "id.valueKey",
              type: "editVar",
              delay: 0,
              value: {
                type: "string",
                value: "tiltUp",
              },
            },
          ],
        },
        {
          name: "向下转动",
          key: "tiltDown",
          eventType: "custom",
          type: "event",
          action: [
            {
              name: "文本",
              key: "id.valueKey",
              type: "editVar",
              delay: 0,
              value: {
                type: "string",
                value: "tiltDown",
              },
            },
          ],
        },
        {
          name: "上下转动停止",
          key: "tiltStop",
          eventType: "custom",
          type: "event",
          action: [
            {
              name: "文本",
              key: "id.valueKey",
              type: "editVar",
              delay: 0,
              value: {
                type: "string",
                value: "tiltStop",
              },
            },
          ],
        },
        {
          name: "转动到中心点",
          key: "ptzHome",
          eventType: "custom",
          type: "event",
          action: [
            {
              name: "文本",
              key: "id.valueKey",
              type: "editVar",
              delay: 0,
              value: {
                type: "string",
                value: "ptzHome",
              },
            },
          ],
        },
        {
          name: "缩放放大",
          key: "zoomIn",
          eventType: "custom",
          type: "event",
          action: [
            {
              name: "文本",
              key: "id.valueKey",
              type: "editVar",
              delay: 0,
              value: {
                type: "string",
                value: "zoomIn",
              },
            },
          ],
        },
        {
          name: "缩放缩小",
          key: "zoomOut",
          eventType: "custom",
          type: "event",
          action: [
            {
              name: "文本",
              key: "id.valueKey",
              type: "editVar",
              delay: 0,
              value: {
                type: "string",
                value: "zoomOut",
              },
            },
          ],
        },
        {
          name: "缩放停止",
          key: "zoomStop",
          eventType: "custom",
          type: "event",
          action: [
            {
              name: "文本",
              key: "id.valueKey",
              type: "editVar",
              delay: 0,
              value: {
                type: "string",
                value: "zoomStop",
              },
            },
          ],
        }
      ],
    };
  }
}
